package com.appkubes.fintech.restful.application.repair;


import com.appkubes.fintech.common.response.Response;
import com.appkubes.fintech.core.po.FintechUserBaseInfo;
import com.appkubes.fintech.restful.application.repair.request.OrderInfoRequest;
import com.appkubes.fintech.restful.application.repair.response.ChannelItemResponse;
import com.appkubes.fintech.restful.application.repair.response.OrderInfoResponse;
import com.appkubes.fintech.restful.application.repair.service.RepairChannelService;
import com.appkubes.fintech.restful.application.repair.service.RepairOrderInfoService;
import com.appkubes.fintech.restful.application.user.dao.UserBaseInfoDao;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @Author: XQC 2020/2/4/11:58
 * @params:
 * @return:
 * @Description:
 **/
@Api(tags = "维修参数")
@Slf4j
@RequestMapping("repair")
@RestController
public class RepairChannelController {

    @Autowired
    private RepairChannelService repairChannelService;

    @Autowired
    private RepairOrderInfoService orderInfoService;
    @Autowired
    private UserBaseInfoDao userBaseInfoDao;

    @ApiOperation("维修项目")
    @GetMapping("item")
    public Response<List<ChannelItemResponse>> billDetail(String code) {
        return repairChannelService.getChannel(code);
    }

    @ApiOperation("保存订单")
    @PostMapping("saveOrder")
    public Response<OrderInfoResponse> saveOrder(@RequestBody OrderInfoRequest request) {
        log.info("参数"+request.toString());
        FintechUserBaseInfo baseInfo=userBaseInfoDao.selectByPrimaryKey(request.getUserId());
        if(baseInfo==null){
            return Response.fail("用户不存在");
        }
        return orderInfoService.saveOrder(request,baseInfo);
    }






}
